from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-18 14:12:47.302573
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 18, Aug, 2021
Time: 14:12:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6924
Nobs: 387.000 HQIC: -46.2479
Log likelihood: 4167.44 FPE: 5.70557e-21
AIC: -46.6129 Det(Omega_mle): 4.53506e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.429912 0.096045 4.476 0.000
L1.Burgenland 0.108604 0.049845 2.179 0.029
L1.Kärnten -0.116233 0.024552 -4.734 0.000
L1.Niederösterreich 0.172262 0.107117 1.608 0.108
L1.Oberösterreich 0.120916 0.105893 1.142 0.254
L1.Salzburg 0.289537 0.051997 5.568 0.000
L1.Steiermark 0.019032 0.068840 0.276 0.782
L1.Tirol 0.114216 0.054286 2.104 0.035
L1.Vorarlberg -0.114840 0.049066 -2.341 0.019
L1.Wien -0.016527 0.094721 -0.174 0.861
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.006206 0.224594 0.028 0.978
L1.Burgenland -0.052114 0.116559 -0.447 0.655
L1.Kärnten 0.034774 0.057413 0.606 0.545
L1.Niederösterreich -0.259104 0.250486 -1.034 0.301
L1.Oberösterreich 0.554584 0.247624 2.240 0.025
L1.Salzburg 0.315056 0.121593 2.591 0.010
L1.Steiermark 0.111064 0.160977 0.690 0.490
L1.Tirol 0.303758 0.126943 2.393 0.017
L1.Vorarlberg -0.011987 0.114738 -0.104 0.917
L1.Wien 0.010117 0.221499 0.046 0.964
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248436 0.048794 5.092 0.000
L1.Burgenland 0.096326 0.025323 3.804 0.000
L1.Kärnten -0.003140 0.012473 -0.252 0.801
L1.Niederösterreich 0.235092 0.054419 4.320 0.000
L1.Oberösterreich 0.155542 0.053798 2.891 0.004
L1.Salzburg 0.036588 0.026417 1.385 0.166
L1.Steiermark 0.011846 0.034973 0.339 0.735
L1.Tirol 0.071010 0.027579 2.575 0.010
L1.Vorarlberg 0.056872 0.024927 2.282 0.023
L1.Wien 0.092534 0.048122 1.923 0.054
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191976 0.047576 4.035 0.000
L1.Burgenland 0.042226 0.024691 1.710 0.087
L1.Kärnten -0.006608 0.012162 -0.543 0.587
L1.Niederösterreich 0.123464 0.053060 2.327 0.020
L1.Oberösterreich 0.313253 0.052454 5.972 0.000
L1.Salzburg 0.101914 0.025757 3.957 0.000
L1.Steiermark 0.139257 0.034100 4.084 0.000
L1.Tirol 0.075213 0.026890 2.797 0.005
L1.Vorarlberg 0.055427 0.024305 2.280 0.023
L1.Wien -0.037015 0.046920 -0.789 0.430
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206855 0.094958 2.178 0.029
L1.Burgenland -0.062791 0.049281 -1.274 0.203
L1.Kärnten -0.036190 0.024274 -1.491 0.136
L1.Niederösterreich 0.083689 0.105905 0.790 0.429
L1.Oberösterreich 0.198438 0.104695 1.895 0.058
L1.Salzburg 0.264614 0.051409 5.147 0.000
L1.Steiermark 0.074860 0.068061 1.100 0.271
L1.Tirol 0.122919 0.053671 2.290 0.022
L1.Vorarlberg 0.115258 0.048511 2.376 0.018
L1.Wien 0.036615 0.093649 0.391 0.696
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.024055 0.074332 0.324 0.746
L1.Burgenland 0.028069 0.038576 0.728 0.467
L1.Kärnten 0.050687 0.019001 2.668 0.008
L1.Niederösterreich 0.199676 0.082901 2.409 0.016
L1.Oberösterreich 0.346247 0.081954 4.225 0.000
L1.Salzburg 0.046849 0.040242 1.164 0.244
L1.Steiermark -0.000676 0.053277 -0.013 0.990
L1.Tirol 0.112887 0.042013 2.687 0.007
L1.Vorarlberg 0.061588 0.037974 1.622 0.105
L1.Wien 0.132181 0.073307 1.803 0.071
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181121 0.090605 1.999 0.046
L1.Burgenland 0.019751 0.047022 0.420 0.674
L1.Kärnten -0.057518 0.023161 -2.483 0.013
L1.Niederösterreich -0.118004 0.101050 -1.168 0.243
L1.Oberösterreich 0.194377 0.099896 1.946 0.052
L1.Salzburg 0.031074 0.049052 0.633 0.526
L1.Steiermark 0.299657 0.064941 4.614 0.000
L1.Tirol 0.492926 0.051211 9.625 0.000
L1.Vorarlberg 0.066097 0.046287 1.428 0.153
L1.Wien -0.106398 0.089357 -1.191 0.234
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161436 0.098631 1.637 0.102
L1.Burgenland -0.004756 0.051187 -0.093 0.926
L1.Kärnten 0.062847 0.025213 2.493 0.013
L1.Niederösterreich 0.195153 0.110001 1.774 0.076
L1.Oberösterreich -0.121140 0.108744 -1.114 0.265
L1.Salzburg 0.244852 0.053397 4.585 0.000
L1.Steiermark 0.154028 0.070693 2.179 0.029
L1.Tirol 0.050329 0.055747 0.903 0.367
L1.Vorarlberg 0.121559 0.050387 2.413 0.016
L1.Wien 0.138949 0.097271 1.428 0.153
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.491211 0.053580 9.168 0.000
L1.Burgenland -0.014884 0.027807 -0.535 0.592
L1.Kärnten -0.009284 0.013697 -0.678 0.498
L1.Niederösterreich 0.199540 0.059757 3.339 0.001
L1.Oberösterreich 0.258448 0.059074 4.375 0.000
L1.Salzburg 0.020745 0.029008 0.715 0.475
L1.Steiermark -0.021685 0.038403 -0.565 0.572
L1.Tirol 0.066409 0.030284 2.193 0.028
L1.Vorarlberg 0.058229 0.027372 2.127 0.033
L1.Wien -0.046231 0.052842 -0.875 0.382
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018395 0.076105 0.142220 0.127385 0.042671 0.069530 0.001395 0.186040
Kärnten 0.018395 1.000000 -0.056081 0.128769 0.045392 0.068185 0.457891 -0.093559 0.097254
Niederösterreich 0.076105 -0.056081 1.000000 0.292748 0.092151 0.275602 0.015388 0.149379 0.258277
Oberösterreich 0.142220 0.128769 0.292748 1.000000 0.175615 0.295494 0.165956 0.120895 0.133775
Salzburg 0.127385 0.045392 0.092151 0.175615 1.000000 0.130149 0.051203 0.109200 0.051468
Steiermark 0.042671 0.068185 0.275602 0.295494 0.130149 1.000000 0.127469 0.087787 -0.019592
Tirol 0.069530 0.457891 0.015388 0.165956 0.051203 0.127469 1.000000 0.039567 0.120289
Vorarlberg 0.001395 -0.093559 0.149379 0.120895 0.109200 0.087787 0.039567 1.000000 -0.047329
Wien 0.186040 0.097254 0.258277 0.133775 0.051468 -0.019592 0.120289 -0.047329 1.000000